# import numpy as np
# from matplotlib import pyplot as plt
#
# # def conv_compute(Data, Weight, para_dict):
# #     pad_h = para_dict['pad_h']
# #     pad_w = para_dict['pad_w']
# #     stride_h = para_dict['stride_h']
# #     stride_w = para_dict['stride_w']
# #
# #     N, _, H, W = Data.shape
# #     C_out = Weight.shape[0]
# #     filter_h = Weight.shape[2]
# #     filter_w = Weight.shape[3]
# #
# #     Data = np.pad(Data, ((0, 0), (0, 0), (pad_h, pad_h), (pad_w, pad_w)), 'constant')
# #
# #     res_h = int(((H + pad_h * 2 - filter_h) / stride_h) + 1)
# #     res_w = int(((W + pad_w * 2 - filter_w) / stride_w) + 1)
# #
# #     res = np.zeros((N, C_out, res_h, res_w))
# #
# #     for n in range(0, N):
# #         for c in range(0, C_out):
# #             res_i = 0
# #             for h in range(0, Data.shape[3] - filter_h + 1, stride_h):
# #                 res_j = 0
# #                 for w in range(0, Data.shape[3] - filter_w + 1, stride_w):
# #                     res[n, c, res_i, res_j] = np.sum(np.multiply(
# #                         Data[n, :, h:h + filter_h, w:w + filter_w], Weight[:, c, :, :]
# #                     ))
# #                     res_j = res_j + 1
# #                 res_i = res_i + 1
# #     return res
# from mindspore import Tensor
# import mindspore as ms
# import mindspore.ops as ops
# from matplotlib import pyplot as plt
#
# ms.set_context(device_target='CPU')
#
#
# def conv_compute1(Data, Weight, para_dict):
#     pad_h = para_dict['pad_h']
#     pad_w = para_dict['pad_w']
#     stride_h = para_dict['stride_h']
#     stride_w = para_dict['stride_w']
#
#     N, _, H, W = Data.shape
#     C_out = Weight.shape[0]
#     filter_h = Weight.shape[2]
#     filter_w = Weight.shape[3]
#
#     Data = np.pad(Data, ((0, 0), (0, 0), (pad_h, pad_h), (pad_w, pad_w)), 'constant')
#
#     res_h = int(((H + pad_h * 2 - filter_h) / stride_h) + 1)
#     res_w = int(((W + pad_w * 2 - filter_w) / stride_w) + 1)
#
#     res = np.zeros((N, C_out, res_h, res_w))
#
#     for n in range(0, N):
#         for c in range(0, C_out):
#             res_i = 0
#             for h in range(0, Data.shape[3] - filter_h + 1, stride_h):
#                 res_j = 0
#                 for w in range(0, Data.shape[3] - filter_w + 1, stride_w):
#                     res[n, c, res_i, res_j] = np.sum(np.multiply(
#                         Data[n, :, h:h + filter_h, w:w + filter_w], Weight[:, c, :, :]
#                     ))
#                     res_j = res_j + 1
#                 res_i = res_i + 1
#     return res
#
#
# def infer_shape(Data, Weight, para):
#     N = Data[0]
#     H = Data[2]
#     W = Data[3]
#
#     C_out = Weight[0]
#     filter_h = Weight[2]
#     filter_w = Weight[3]
#
#     pad_h = para[0]
#     pad_w = para[1]
#     stride_h = para[2]
#     stride_w = para[3]
#
#     res_h = int(((H + 2 * pad_h - filter_h) / stride_h) + 1)
#     res_w = int(((W + 2 * pad_w - filter_w) / stride_w) + 1)
#
#     return (N, C_out, res_h, res_w)
#
#
# def infer_dtype(Data, weight, para):
#     return Data
#
#
# op=ops.Custom(conv_compute1,
#               out_shape=infer_shape,
#               out_dtype=infer_dtype,
#               func_type='pyfunc')

# %%writefile cus_add3.py
from mindspore.ops import prim_attr_register ,PrimitiveWithInfer
class CusAdd3(PrimitiveWithInfer):
    @prim_attr_register
    def __int__(self,const_bias=0.0):
        self.init_prim_io_names(inputs=['input1','input2'],outputs=['sum3'])
        # from add3_im